package com.dao.impl;

import com.dao.OrderDao;
import com.javabean.Order;

import java.util.List;


public class OrderDaoImpl extends BaseDao implements OrderDao {
    @Override
    public int saveOrder(Order order) {
        String sql = "insert into t_order(`orderid`,`createtime`,`price`,`status`,`userid`) values(?,?,?,?,?)";
        return update(sql, order.getOrderId(), order.getCreateTime(), order.getPrice(), order.getStatus(), order.getUserId());

    }

    @Override
    public List<Order> queryOrders() {
        String sql = "select * from t_order";
        return queryForList(Order.class, sql);
    }

    @Override
    public int changeOrderStatus(String orderid, Integer status) {
        String sql = "update t_order set `status`=? where orderid=?";
        return update(sql, status, orderid);
    }

    @Override
    public List<Order> queryOrdersByUserId(Integer userId) {
        String sql = "select * from t_order where userid=?";
        return queryForList(Order.class, sql, userId);
    }
}
